package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.model.user.UserPaidTrack;
import com.atguigu.tingshu.user.service.UserInfoService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	@GetMapping("queryUserById/{userId}")
	public Result<UserInfo> queryUserById(@PathVariable Long userId){
		UserInfo userInfo = this.userInfoService.getById(userId);
		return Result.ok(userInfo);
	}

	@GuiGuLogin
	@GetMapping("isPaidAlbum/{albumId}")
	public Result<Boolean> isPaidAlbum(@PathVariable Long albumId){

		Boolean flag = this.userInfoService.isPaidAlbum(albumId);
		return Result.ok(flag);
	}

	@GuiGuLogin
	@GetMapping("getPaidTracks/{albumId}")
	public Result<List<UserPaidTrack>> getPaidTracks(@PathVariable Long albumId){
		List<UserPaidTrack> userPaidTracks = this.userInfoService.getPaidTracks(albumId);
		return Result.ok(userPaidTracks);
	}

	@PostMapping("updateExpiredVipStatus")
	public Result updateExpiredVipStatus(){
		this.userInfoService.updateExpiredVipStatus();
		return Result.ok();
	}
}

